﻿@model ForumPageModel
@using Nop.Core.Domain.Forums;
@using Nop.Services.Customers;
@using Nop.Services.Forums;
@using Nop.Services.Seo;
@using Nop.Web;
@using Nop.Web.Extensions;
@using Nop.Web.Models;
@using Nop.Web.Models.Boards;
@using Nop.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    Html.AddTitleParts(Model.Name);
}
<script type="text/javascript">
    function handleForumWatch(context) {
        $('#watchforum').text(context.Text);
    }
</script>
<div class="forum">
    @Html.Action("ForumBreadcrumb", new { forumId = Model.Id })
    <div class="top">
        <div class="foruminfo">
            <span class="forumname">
                @Model.Name</span>
            <br />
            <span class="forumdescription">
                @Model.Description</span>
            <br />
            @if (Model.ForumFeedsEnabled)
            {            
                <a href="@Url.RouteUrl("ForumRSS", new { id = @Model.Id })">
                    <img title="@T("Forum.ForumRSSLinkTitle")" src="@Url.Content("~/content/images/icon_rss.gif")" alt="@T("Forum.RSS")" /></a>
            }
        </div>
        <div class="actions">
            @Html.RouteLink(@T("Forum.NewTopic").ToString(), "TopicCreate", new { id = @Model.Id }, new { @class = "newtopic" })
            @if (Model.IsCustomerAllowedToSubscribe)
            {
                @Ajax.RouteLink(Model.WatchForumText,
                                "ForumWatch",
                                new { id = @Model.Id },
                                new AjaxOptions { HttpMethod = "Post", OnSuccess = "handleForumWatch" },
                                new { id = "watchforum", @class = "watchforum" })
            }
            <br />
            @Html.Partial("_SearchBox")
        </div>
    </div>
    <div class="clear">
    </div>
    <div class="pager">
        @{
            var pager = @Html.Pager(new PagerModel()
            {
                PageSize = Model.TopicPageSize,
                TotalRecords = Model.TopicTotalRecords,
                PageIndex = Model.TopicPageIndex,
                ShowTotalSummary = false,
                RouteActionName = "ForumSlugPaged",
                UseRouteLinks = true,
                RouteValues = new RouteValues { id = Model.Id, slug = Model.SeName }
            });
        }
        @pager
    </div>
    <div class="clear">
    </div>
    <div class="topicsgroup">
        <table class="topics">
            @if (Model.ForumTopics.Count > 0)
            {
                <tr class="forumheader">
                    <td class="topicname" colspan="2">
                        @T("Forum.TopicTitle")
                    </td>
                    <td class="replies">
                        @T("Forum.Replies")
                    </td>
                    <td class="views">
                        @T("Forum.Views")
                    </td>
                    <td class="lastpost">
                        @T("Forum.LatestPost")
                    </td>
                </tr>
            }
            @foreach (var topic in @Model.ForumTopics)
            {
                <tr class="topic">
                    <td>
                        @{
                var topicType = "post";
                var topicText = String.Empty;
                switch (topic.ForumTopicType)
                {
                    case ForumTopicType.Normal:
                        topicType = "post";
                        break;
                    case ForumTopicType.Sticky:
                        topicType = "poststicky";
                        topicText = string.Format("[{0}]", @T("Forum.Sticky").ToString());
                        break;
                    case ForumTopicType.Announcement:
                        topicType = "postannoucement";
                        topicText = string.Format("[{0}]", @T("Forum.Announcement").ToString());
                        break;
                    default:
                        topicType = "post";
                        break;
                }
                            <div class="@topicType">
                            </div>
                        }
                    </td>
                    <td class="topicname">
                        @if (!String.IsNullOrEmpty(@topicText))
                        {
                            <span class="topictype">@topicText</span>
                        }
                        @Html.RouteLink(@topic.Subject, "TopicSlug", new { id = @topic.Id, slug = @topic.SeName }, new { @class = "topictitle" })
                        <br />
                        @if (@topic.NumPosts > Model.PostsPageSize)
                        {   
                            <span class="topicspager">
                                @Html.ForumTopicSmallPager(topic)
                            </span>
                            <br />
                        }
                        <span class="topicstarter">
                            @if (@topic.CustomerId > 0)
                            {
                                if (topic.AllowViewingProfiles && !topic.IsCustomerGuest)
                                {
                                    @T("Forum.Author")<text>:</text> @Html.RouteLink(topic.CustomerName, "CustomerProfile", new { Id = topic.CustomerId })
                                }
                                else
                                {
                                    @T("Forum.Author")<text>:</text> @topic.CustomerName
                                }
                            }
                        </span>
                    </td>
                    <td class="replies">
                        @topic.NumReplies
                    </td>
                    <td class="views">
                        @topic.Views
                    </td>
                    <td class="lastpost">
                        @Html.Action("LastPost", new { forumPostId = @topic.LastPostId, showTopic = false })
                    </td>
                </tr>
            }
        </table>
    </div>
    <div class="clear">
    </div>
    <div class="pager">
        @pager
    </div>
</div>
